home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / xcdplayer / button_setup.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  16KB  |  626 lines

  1. /*
  2.  * Copyright (C) 1990 Regents of the University of California.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of the University of
  9.  * California not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  the University of California makes no representations
  12.  * about the suitability of this software for any purpose.  It is provided
  13.  * "as is" without express or implied warranty.
  14.  */
  15.  
  16. #include <stdio.h>
  17. # include <X11/Intrinsic.h>
  18. # include <X11/StringDefs.h>
  19. # include <X11/Xaw/Form.h>
  20. # include <X11/Xaw/Toggle.h>
  21.  
  22. # include "cdrom_globs.h"
  23. #ifdef sun
  24. # include "cdrom_sun.h"
  25. #endif
  26. #ifdef sgi
  27. # include "cdrom_sgi.h"
  28. #endif
  29.  
  30. # include "play.xbm"
  31. # include "pause.xbm"
  32. # include "stop.xbm"
  33. # include "prev.xbm"
  34. # include "next.xbm"
  35. # include "eject.xbm"
  36. #ifdef sgi
  37. # include "audio.xbm"
  38. #endif
  39.  
  40. # include "quit.xbm"
  41. # include "cycle.xbm"
  42. # include "shuffle.xbm"
  43. # include "rewind.xbm"
  44. # include "ff.xbm"
  45. # include "pgm.xbm"
  46.  
  47.  
  48. static Widget    buttons_form_widget;
  49. static Widget    play_button_widget;
  50. static Widget    stop_button_widget;
  51. static Widget    pause_button_widget;
  52. static Widget    eject_button_widget;
  53. #ifdef sgi
  54. static Widget    audio_button_widget;
  55. #endif
  56. static Widget    shuffle_button_widget;
  57. static Widget    cycle_button_widget;
  58. static Widget    pgm_button_widget;
  59.  
  60. /* 
  61.  * these are global for the "scan" functions to query their state;
  62.  * they and the code that they work with should probably be be switched
  63.  * to repeater widgets once R5 becomes universal...
  64.  */
  65. Widget    rew_button_widget;
  66. Widget    ff_button_widget;
  67.  
  68.  
  69. void
  70. button_setup(parent_widget)
  71.     Widget        parent_widget;
  72. {
  73.     Arg        args[1];
  74.  
  75.     extern void    title_dialog_setup();
  76.     extern void    play_button_setup();
  77.     extern void    stop_button_setup();
  78.     extern void    pause_button_setup();
  79.     extern void    prev_button_setup();
  80.     extern void    next_button_setup();
  81.     extern void    eject_button_setup();
  82. #ifdef sgi
  83.     extern void    audio_button_setup();
  84. #endif
  85.     extern void    quit_button_setup();
  86.     extern void    cycle_button_setup();
  87.     extern void    shuffle_button_setup();
  88.     extern void    rew_button_setup();
  89.     extern void    ff_button_setup();
  90.     extern void    pgm_button_setup();
  91.     extern void    buttons_reset();
  92.  
  93.  
  94.     buttons_form_widget = XtCreateManagedWidget("buttonsForm",
  95.                             formWidgetClass,
  96.                             parent_widget,
  97.                             (ArgList) NULL, 0);
  98.  
  99.     play_button_setup(buttons_form_widget);
  100.  
  101.     pause_button_setup(buttons_form_widget);
  102.  
  103.     stop_button_setup(buttons_form_widget);
  104.  
  105.     prev_button_setup(buttons_form_widget);
  106.  
  107.     next_button_setup(buttons_form_widget);
  108.  
  109.     eject_button_setup(buttons_form_widget);
  110.  
  111. #ifdef sgi
  112.     audio_button_setup(buttons_form_widget);
  113. #endif
  114.  
  115.     quit_button_setup(buttons_form_widget);
  116.  
  117.     cycle_button_setup(buttons_form_widget);
  118.  
  119.     shuffle_button_setup(buttons_form_widget);
  120.  
  121.     rew_button_setup(buttons_form_widget);
  122.  
  123.     ff_button_setup(buttons_form_widget);
  124.  
  125.     pgm_button_setup(buttons_form_widget);
  126.  
  127.  
  128.     /* set the initial state of the buttons */
  129.     buttons_reset();
  130. }
  131.  
  132. static void
  133. play_button_setup(parent_widget)
  134.     Widget        parent_widget;
  135. {
  136.     Pixmap        play_button_pixmap;
  137.     Arg        args[1];
  138.  
  139.     play_button_widget = XtCreateManagedWidget("playButton",
  140.                            toggleWidgetClass,
  141.                            parent_widget,
  142.                            (ArgList) NULL, 0);
  143.  
  144.     play_button_pixmap = XCreateBitmapFromData(XtDisplay(play_button_widget),
  145.                            rootwin(play_button_widget),
  146.                            play_bits,
  147.                            play_width, play_height);
  148.  
  149.     XtSetArg(args[0], XtNbitmap, (XtArgVal) play_button_pixmap);
  150.     XtSetValues(play_button_widget, args, 1);
  151.  
  152.     XtAddCallback(play_button_widget, XtNcallback, cb_cdrom_play, 0);
  153.  
  154. }
  155.  
  156. static void
  157. pause_button_setup(parent_widget)
  158.     Widget        parent_widget;
  159. {
  160.     Pixmap        pause_button_pixmap;
  161.     Arg        args[1];
  162.  
  163.     pause_button_widget = XtCreateManagedWidget("pauseButton",
  164.                             toggleWidgetClass,
  165.                             parent_widget,
  166.                             (ArgList) NULL, 0);
  167.  
  168.     pause_button_pixmap = XCreateBitmapFromData(XtDisplay(pause_button_widget),
  169.                             rootwin(pause_button_widget),
  170.                             pause_bits,
  171.                             pause_width, pause_height);
  172.  
  173.     XtSetArg(args[0], XtNbitmap, (XtArgVal) pause_button_pixmap);
  174.     XtSetValues(pause_button_widget, args, 1);
  175.  
  176.     XtAddCallback(pause_button_widget, XtNcallback, cb_cdrom_pause, 0);
  177. }
  178.  
  179. static void
  180. stop_button_setup(parent_widget)
  181.     Widget        parent_widget;
  182. {
  183.     Pixmap        stop_button_pixmap;
  184.     Arg        args[1];
  185.  
  186.     stop_button_widget = XtCreateManagedWidget("stopButton",
  187.                            toggleWidgetClass,
  188.                            parent_widget,
  189.                            (ArgList) NULL, 0);
  190.  
  191.     stop_button_pixmap = XCreateBitmapFromData(XtDisplay(stop_button_widget),
  192.                            rootwin(stop_button_widget),
  193.                            stop_bits,
  194.                            stop_width, stop_height);
  195.  
  196.     XtSetArg(args[0], XtNbitmap, (XtArgVal) stop_button_pixmap);
  197.     XtSetValues(stop_button_widget, args, 1);
  198.  
  199.     XtAddCallback(stop_button_widget, XtNcallback, cb_cdrom_stop, 0);
  200.  
  201. }
  202.  
  203. static void
  204. prev_button_setup(parent_widget)
  205.     Widget        parent_widget;
  206. {
  207.     Widget        prev_button_widget;
  208.     Pixmap        prev_button_pixmap;
  209.     Arg        args[1];
  210.  
  211.     prev_button_widget = XtCreateManagedWidget("prevButton",
  212.                           toggleWidgetClass,
  213.                           parent_widget,
  214.                           (ArgList) NULL, 0);
  215.  
  216.     prev_button_pixmap = XCreateBitmapFromData(XtDisplay(prev_button_widget),
  217.                           rootwin(prev_button_widget),
  218.                           prev_bits,
  219.                           prev_width, prev_height);
  220.  
  221.     XtSetArg(args[0], XtNbitmap, (XtArgVal) prev_button_pixmap);
  222.     XtSetValues(prev_button_widget, args, 1);
  223.  
  224.     XtAddCallback(prev_button_widget, XtNcallback, cb_cdrom_previous, 0);
  225. }
  226.  
  227. static void
  228. next_button_setup(parent_widget)
  229.     Widget        parent_widget;
  230. {
  231.     Widget        next_button_widget;
  232.     Pixmap        next_button_pixmap;
  233.     Arg        args[1];
  234.  
  235.     next_button_widget = XtCreateManagedWidget("nextButton",
  236.                          toggleWidgetClass,
  237.                          parent_widget,
  238.                          (ArgList) NULL, 0);
  239.  
  240.     next_button_pixmap = XCreateBitmapFromData(XtDisplay(next_button_widget),
  241.                          rootwin(next_button_widget),
  242.                          next_bits,
  243.                          next_width, next_height);
  244.  
  245.     XtSetArg(args[0], XtNbitmap, (XtArgVal) next_button_pixmap);
  246.     XtSetValues(next_button_widget, args, 1);
  247.  
  248.     XtAddCallback(next_button_widget, XtNcallback, cb_cdrom_next, 0);
  249. }
  250.  
  251. static void
  252. eject_button_setup(parent_widget)
  253.     Widget        parent_widget;
  254. {
  255.     Pixmap        eject_button_pixmap;
  256.     Arg        args[1];
  257.  
  258.     eject_button_widget = XtCreateManagedWidget("ejectButton",
  259.                             toggleWidgetClass,
  260.                             parent_widget,
  261.                             (ArgList) NULL, 0);
  262.  
  263.     eject_button_pixmap = XCreateBitmapFromData(XtDisplay(eject_button_widget),
  264.                             rootwin(eject_button_widget),
  265.                             eject_bits,
  266.                             eject_width, eject_height);
  267.  
  268.     XtSetArg(args[0], XtNbitmap, (XtArgVal) eject_button_pixmap);
  269.     XtSetValues(eject_button_widget, args, 1);
  270.  
  271.     XtAddCallback(eject_button_widget, XtNcallback, cb_cdrom_eject, 0);
  272. }
  273.  
  274. #ifdef sgi
  275. static void
  276. audio_button_setup(parent_widget)
  277.     Widget        parent_widget;
  278. {
  279.     Pixmap        audio_button_pixmap;
  280.     Arg        args[1];
  281.  
  282.     audio_button_widget = XtCreateManagedWidget("audioButton",
  283.                             toggleWidgetClass,
  284.                             parent_widget,
  285.                             (ArgList) NULL, 0);
  286.  
  287.     audio_button_pixmap = XCreateBitmapFromData(XtDisplay(audio_button_widget),
  288.                             rootwin(audio_button_widget),
  289.                             audio_bits,
  290.                             audio_width, audio_height);
  291.  
  292.     XtSetArg(args[0], XtNbitmap, (XtArgVal) audio_button_pixmap);
  293.     XtSetValues(audio_button_widget, args, 1);
  294.  
  295.     XtAddCallback(audio_button_widget, XtNcallback, cb_cdrom_audio, 0);
  296. }
  297. #endif
  298.  
  299. static void
  300. quit_button_setup(parent_widget)
  301.     Widget        parent_widget;
  302. {
  303.     Widget        quit_button_widget;
  304.     Pixmap        quit_button_pixmap;
  305.     Arg        args[1];
  306.  
  307.     quit_button_widget = XtCreateManagedWidget("quitButton",
  308.                             toggleWidgetClass,
  309.                             parent_widget,
  310.                             (ArgList) NULL, 0);
  311.  
  312.     quit_button_pixmap = XCreateBitmapFromData(XtDisplay(quit_button_widget),
  313.                             rootwin(quit_button_widget),
  314.                             quit_bits,
  315.                             quit_width, quit_height);
  316.  
  317.     XtSetArg(args[0], XtNbitmap, (XtArgVal) quit_button_pixmap);
  318.     XtSetValues(quit_button_widget, args, 1);
  319.  
  320.     XtAddCallback(quit_button_widget, XtNcallback, cb_cdrom_quit, 0);
  321. }
  322.  
  323. static void
  324. cycle_button_setup(parent_widget)
  325.     Widget        parent_widget;
  326. {
  327.     Widget        cycle_button_widget;
  328.     Pixmap        cycle_button_pixmap;
  329.     Arg        args[1];
  330.  
  331.     cycle_button_widget = XtCreateManagedWidget("cycleButton",
  332.                             toggleWidgetClass,
  333.                             parent_widget,
  334.                             (ArgList) NULL, 0);
  335.  
  336.     cycle_button_pixmap = XCreateBitmapFromData(XtDisplay(cycle_button_widget),
  337.                             rootwin(cycle_button_widget),
  338.                             cycle_bits,
  339.                             cycle_width, cycle_height);
  340.  
  341.     XtSetArg(args[0], XtNbitmap, (XtArgVal) cycle_button_pixmap);
  342.     XtSetValues(cycle_button_widget, args, 1);
  343.  
  344.     XtAddCallback(cycle_button_widget, XtNcallback, cb_cdrom_cycle, 0);
  345. }
  346.  
  347. static void
  348. shuffle_button_setup(parent_widget)
  349.     Widget        parent_widget;
  350. {
  351.     Pixmap        shuffle_button_pixmap;
  352.     Arg        args[1];
  353.  
  354.     shuffle_button_widget = XtCreateManagedWidget("shuffleButton",
  355.                               toggleWidgetClass,
  356.                               parent_widget,
  357.                               (ArgList) NULL, 0);
  358.  
  359.     shuffle_button_pixmap = XCreateBitmapFromData(XtDisplay(shuffle_button_widget),
  360.                               rootwin(shuffle_button_widget),
  361.                               shuffle_bits,
  362.                               shuffle_width, shuffle_height);
  363.  
  364.     XtSetArg(args[0], XtNbitmap, (XtArgVal) shuffle_button_pixmap);
  365.     XtSetValues(shuffle_button_widget, args, 1);
  366.  
  367.     XtAddCallback(shuffle_button_widget, XtNcallback, cb_cdrom_shuffle, 0);
  368. }
  369.  
  370.  
  371. static void
  372. rew_button_setup(parent_widget)
  373.         Widget          parent_widget;
  374. {
  375.         Pixmap          rew_button_pixmap;
  376.         Arg             args[1];
  377.  
  378.         rew_button_widget = XtCreateManagedWidget("rewButton",
  379.                                                   toggleWidgetClass,
  380.                                                   parent_widget,
  381.                                                   (ArgList) NULL, 0);
  382.  
  383.         rew_button_pixmap = XCreateBitmapFromData(XtDisplay(rew_button_widget),
  384.                                                   rootwin(rew_button_widget),
  385.                                                   rewind_bits,
  386.                                                   rewind_width, rewind_height);
  387.  
  388.         XtSetArg(args[0], XtNbitmap, (XtArgVal) rew_button_pixmap);
  389.         XtSetValues(rew_button_widget, args, 1);
  390.  
  391.         XtAddCallback(rew_button_widget, XtNcallback, cb_cdrom_rewind, 0);
  392. }
  393.  
  394.  
  395.  
  396. static void
  397. ff_button_setup(parent_widget)
  398.         Widget          parent_widget;
  399. {
  400.         Pixmap          ff_button_pixmap;
  401.         Arg             args[1];
  402.  
  403.         ff_button_widget = XtCreateManagedWidget("ffButton",
  404.                                                  toggleWidgetClass,
  405.                                                  parent_widget,
  406.                                                  (ArgList) NULL, 0);
  407.  
  408.         ff_button_pixmap = XCreateBitmapFromData(XtDisplay(ff_button_widget),
  409.                                                  rootwin(ff_button_widget),
  410.                                                  ff_bits,
  411.                                                  ff_width, ff_height);
  412.  
  413.         XtSetArg(args[0], XtNbitmap, (XtArgVal) ff_button_pixmap);
  414.         XtSetValues(ff_button_widget, args, 1);
  415.  
  416.         XtAddCallback(ff_button_widget, XtNcallback, cb_cdrom_ff, 0);
  417. }
  418.  
  419. static void
  420. pgm_button_setup(parent_widget)
  421.         Widget          parent_widget;
  422. {
  423.         Pixmap          pgm_button_pixmap;
  424.         Arg             args[1];
  425.     extern Widget    top_form;
  426.  
  427.         pgm_button_widget = XtCreateManagedWidget("pgmButton",
  428.                                                  toggleWidgetClass,
  429.                                                  parent_widget,
  430.                                                  (ArgList) NULL, 0);
  431.  
  432.         pgm_button_pixmap = XCreateBitmapFromData(XtDisplay(pgm_button_widget),
  433.                                                  rootwin(pgm_button_widget),
  434.                                                  pgm_bits,
  435.                                                  pgm_width, pgm_height);
  436.  
  437.         XtSetArg(args[0], XtNbitmap, (XtArgVal) pgm_button_pixmap);
  438.         XtSetValues(pgm_button_widget, args, 1);
  439.  
  440.         XtAddCallback(pgm_button_widget, XtNcallback, cb_cdrom_program,
  441.         (XtPointer) top_form);
  442. }
  443.  
  444. void
  445. play_button_set() {
  446.     Arg        args[1];
  447.  
  448.     XtSetArg(args[0], XtNstate, True);
  449.     XtSetValues(play_button_widget, args, 1);
  450. }
  451.  
  452. void
  453. play_button_reset() {
  454.     Arg        args[1];
  455.  
  456.     XtSetArg(args[0], XtNstate, False);
  457.     XtSetValues(play_button_widget, args, 1);
  458. }
  459.  
  460. void
  461. pause_button_reset() {
  462.     Arg        args[1];
  463.  
  464.     XtSetArg(args[0], XtNstate, False);
  465.     XtSetValues(pause_button_widget, args, 1);
  466. }
  467.  
  468. void
  469. stop_button_reset() {
  470.     Arg        args[1];
  471.  
  472.     XtSetArg(args[0], XtNstate, False);
  473.     XtSetValues(stop_button_widget, args, 1);
  474. }
  475.  
  476. void
  477. eject_button_reset() {
  478.     Arg        args[1];
  479.  
  480.     XtSetArg(args[0], XtNstate, False);
  481.     XtSetValues(eject_button_widget, args, 1);
  482. }
  483.  
  484. void
  485. eject_button_set() {
  486.     Arg        args[1];
  487.  
  488.     XtSetArg(args[0], XtNstate, True);
  489.     XtSetValues(eject_button_widget, args, 1);
  490. }
  491.  
  492. #ifdef sgi
  493. void
  494. audio_button_reset() {
  495.     Arg        args[1];
  496.  
  497.     XtSetArg(args[0], XtNstate, False);
  498.     XtSetValues(audio_button_widget, args, 1);
  499. }
  500.  
  501. void
  502. audio_button_set() {
  503.     Arg        args[1];
  504.  
  505.     XtSetArg(args[0], XtNstate, True);
  506.     XtSetValues(audio_button_widget, args, 1);
  507. }
  508.  
  509. int
  510. audio_button_state() {
  511.     Arg        args[1];
  512.     Boolean        state;
  513.  
  514.     XtSetArg(args[0], XtNstate, &state);
  515.     XtGetValues(audio_button_widget, args, 1);
  516.     return(state);
  517. }
  518. #endif
  519.  
  520. void
  521. shuffle_button_set() {
  522.     Arg        args[1];
  523.  
  524.     XtSetArg(args[0], XtNstate, True);
  525.     XtSetValues(shuffle_button_widget, args, 1);
  526. }
  527.  
  528. void
  529. shuffle_button_reset() {
  530.     Arg        args[1];
  531.  
  532.     XtSetArg(args[0], XtNstate, False);
  533.     XtSetValues(shuffle_button_widget, args, 1);
  534. }
  535.  
  536. void
  537. cycle_button_reset() {
  538.     Arg        args[1];
  539.  
  540.     XtSetArg(args[0], XtNstate, False);
  541.     XtSetValues(cycle_button_widget, args, 1);
  542. }
  543.  
  544. void
  545. pgm_button_set() {
  546.     Arg        args[2];
  547.  
  548.     XtSetArg(args[0], XtNstate, True);
  549.     XtSetValues(pgm_button_widget, args, 1);
  550. }
  551.  
  552. void
  553. pgm_button_reset() {
  554.     Arg        args[2];
  555.  
  556.     XtSetArg(args[0], XtNstate, False);
  557.     XtSetValues(pgm_button_widget, args, 1);
  558. }
  559.  
  560. void
  561. buttons_reset() {
  562.     Arg        args[2];
  563. #ifdef sun
  564.     Boolean        state;
  565. #endif
  566.  
  567. #ifdef sgi
  568.     if (cdi.scsi_audio) {
  569.         XtSetArg(args[0], XtNstate, True);
  570.         XtSetValues(audio_button_widget, args, 1);
  571.     } else {
  572.         XtSetArg(args[0], XtNstate, False);
  573.         XtSetValues(audio_button_widget, args, 1);
  574.     }
  575. #endif
  576.  
  577.     switch (cdrom_status()) {
  578.     case -1:
  579.         XtSetArg(args[0], XtNstate, True);
  580.         XtSetValues(eject_button_widget, args, 1);
  581.         cdi.state |= CDROM_STATE_EJECTED;
  582.         disc_title = NODISCSTR;
  583.         update_title();
  584.         break;
  585.  
  586.     case CDROM_PLAYING:
  587.         XtSetArg(args[0], XtNstate, True);
  588.         XtSetValues(play_button_widget, args, 1);
  589.         cdi.state |= CDROM_STATE_PLAY;
  590.         cdrom_timer_on();
  591.         break;
  592.  
  593.     case CDROM_PAUSED:
  594. #ifdef sun
  595.         /* 
  596.          * The Sun doesn't have a "stop" state, so handle the
  597.          * initial startup condition.
  598.          */
  599.         XtSetArg(args[0], XtNstate, &state);
  600.         XtGetValues(pause_button_widget, args, 1);
  601.         if (state == False) {
  602.             XtSetArg(args[0], XtNstate, True);
  603.             XtSetValues(stop_button_widget, args, 1);
  604.             cdi.state |= CDROM_STATE_STOP;
  605.             break;
  606.         } 
  607. #endif
  608.         XtSetArg(args[0], XtNstate, True);
  609.         XtSetValues(play_button_widget, args, 1);
  610.         XtSetArg(args[0], XtNstate, True);
  611.         XtSetValues(pause_button_widget, args, 1);
  612.         cdi.state |= CDROM_STATE_PLAY;
  613.         cdi.curtrack = cdrom_get_curtrack();
  614.         track_button_update(); /* make track button read on startup */
  615.         timer_button_update(); /* make timer button read on startup */
  616.         cdi.state |= CDROM_STATE_PAUSE;
  617.         break;
  618.  
  619.     default:
  620.         XtSetArg(args[0], XtNstate, True);
  621.         XtSetValues(stop_button_widget, args, 1);
  622.         cdi.state |= CDROM_STATE_STOP;
  623.         break;
  624.     }
  625. }
  626.